﻿using log4net;
using log4net.Repository.Hierarchy;
using Microsoft.EntityFrameworkCore;
using OAuth.EFCore.Common;
using OAuth.EFCore.Interface;
using OAuth.EFCore.Model;
using System;
using System.Threading.Tasks;

namespace OAuth.EFCore.Service
{
    public class SSM01Service: ISSM01
    {
        private ILog _log ;

        private readonly DataContext _db;

        public SSM01Service(DataContext db, ILog log)
        {
            _db = db;
            _log = log;
        }

        public async Task<bool> AddUser(User user)
        {
            User result = await _db.Users.SingleOrDefaultAsync(r=>r.userName == user.userName);
            if (result != null)
                throw new Exception("SSM01Service||AddUser||当前用户已存在");
            user.Create();
            await _db.Users.AddAsync(user);
            await _db.SaveChangesAsync();
            return true;
        }





    }
}
